package src.mian.java;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class HDFSFileUpload {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS", "hdfs://192.168.254.100:8020");  // 设置HDFS的地址

        try {
            FileSystem fs = FileSystem.get(conf);
            Path localFilePath = new Path("/D:/hadoop/world.txt");  // 本地文件路径
            Path hdfsFilePath = new Path("/test/");  // HDFS文件路径

            fs.copyFromLocalFile(localFilePath, hdfsFilePath);  // 上传文件到HDFS

            fs.close();
            System.out.println("File uploaded to HDFS successfully");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
